<template>
	<yd-layout id='articleDetail' class=''>
		<!--<a href="tel:17380559502">cccccc</a>-->
		<div class="content" v-if="isShow">
			<div class="title">{{dataObj.title}}</div>
			<div class="label" >
				<span>
					<img src="../../assets/index_look.png" alt="" />
					<div>{{dataObj.pv}}次</div>
					<!--{{dataObj.newTime}}-->
				</span>
				<div v-if='dataObj.collected==1'  style='background: #999999;' class="btn" @click="collect(1)">已收藏</div>
				<div  v-else class="btn" @click="collect">收藏</div>
				
			</div>
			<div class="c_v_html " v-html="dataObj.content"></div>
			<!--<iframe style="width: 100%;height: fit-content;" :src="'http://wst.aiwst.cn/bangyang/article/content?id='+$route.query.id" width="" height=""></iframe>-->
			<div class="share_car_f" v-if="$route.query.uid&&false">
				<div class="share_car_title">
					<span></span>
					<div>联系我了解更多</div>
					<span></span>
				</div>
				<div class="share_car">
					<img class="share_car_img" :src="userObj.avatar" alt="" />
					<div class="share_car_name">{{userObj.nick_name}}</div>
					<div class="share_car_label">{{userObj.summary}}</div>
					<div class="share_car_btn">
						<div class="share_car_btn_c" @click="qrCodeShow = true">
							<img class="share_car_btn_img" src="../../assets/article_1.png" alt="" />
							<div>+微信</div>
						</div>
						<a :href="'tel:'+userObj.mobile" class="share_car_btn_c" style="background: #35BF7E;">
							<img class="share_car_btn_img" src="../../assets/article_2.png" alt="" />
							<div>打电话</div>
						</a>
					</div>
				</div>
			</div>
		</div>
		<div v-else class="no_artic_c">
			<div class="no_artic">
				<div class="no_artic_1">无法访问该文章</div>
				<div class="no_artic_btn" @click="$router.push({name:'index'})">回首页</div>
			</div>
		</div>
		
		 <yd-popup v-model="popFlg" position="center" width="90%">
            <div class="qr_pop">
            	<div class="pop_top">
            		<img class="pop_top_img" :src="userObj.wechat_code" alt="" />
            		<div class="pop_top_label">长按上方二维码扫描添加好友</div>
            	</div>
            	<img @click="qrCodeShow=false" class="pop_close_img" src="../../assets/close_1.png" alt="" />
            </div>
        </yd-popup>
	</yd-layout>
</template>

<script>
	import {Popup} from 'vue-ydui/dist/lib.rem/popup';
	export default{
		components:{
			[Popup.name]:Popup
		},
		data(){
			return {
				popFlg:false,
				btnStr:true,
				dataObj:{},
				isShow:true,
				qrCodeShow:false,
				userObj:{}
			}
		},
		created() {
//			var html =document.querySelector('html');
//      	html.style.fontSize = '16px';
        	
			console.log(this.$root.userInfo)
			if(this.$root.userInfo&&JSON.stringify(this.$root.userInfo)!='{}'){
				this.$root.id = this.$route.query.id 
				this.$root.uuid = (parseInt((parseInt(new Date()-0))/1000))+''+(this.$root.userInfo.me.id||0)
				this.$root.submitEvent({
					kind:1,
				})
				this.$store.commit({
					type:'setDataEvent',
					data:{
						kind:1,
						position:0,
						oid:this.$route.query.id,
						uuid:this.$root.uuid,
						uid:this.$root.userInfo&&(JSON.stringify(this.$root.userInfo)!='{}')?this.$root.userInfo.me.id:0
					}
				})
			}
				
		},
		//销毁实例
		beforeDestroy(){
			
//			var winWidth = window.innerWidth;
//	        var html =document.querySelector('html');
//      	html.style.fontSize = (winWidth / 750) * 100 + 'px';
        	if(this.$root.userInfo&&JSON.stringify(this.$root.userInfo)!='{}'){
        		this.$root.submitEvent({
					kind:1,
					lastFlg:true,
				})
        	}
	        
		},
		watch: {
			
		},
		computed: {
			
		},
		
		mounted(){
			
			document.title='文章详情'
			this.articleDetail()
			if(this.$route.query.uid){
				this.$root.ajax({
					name:'my/namecard',
					type:'post',
					params:{
						uid:this.$route.query.uid
					}
				}).then((d)=>{
					this.userObj = Object.assign({},this.userObj,d.data)
				})
			}
			
//			this.$root.ajax({
//					name:'article/content',
//					type:'post',
//					params:{
//						id:this.$route.query.id
//					}
//				}).then((d)=>{
//					
//				})
		},
		methods:{
			collect(num){
				let name = ''
				let loadingName = ''
				if(num==1){
					name = 'collection/cancel'
					loadingName = '请稍后...' //取消收藏中，请稍后...
				}else{
					name = 'collection/collect'
					loadingName = '请稍后...' //收藏中，请稍后...
				}
				this.$root.ajax({
					name:name,
					//closeAllLoading:true,
					loadingName:loadingName,
					params:{
						kind:1,
						oid:this.$route.query.id
					}
				}).then((d)=>{
					if(num==1){
						this.dataObj.collected = 0
						this.$dialog.toast({
		                    mes: '取消收藏',
		                    timeout: 500
		                });
					}else{
						this.dataObj.collected = 1
						
		                this.$dialog.toast({
		                    mes: '收藏成功',
		                    timeout: 500
		                });
					}
				})
			},
			articleDetail(){
				this.$root.ajax({
					name:'article/detail',
					type:'get',
					params:{
						id:this.$route.query.id
					}
				}).then((d)=>{
					if(d.data){
						d.data.newTime = this.$root.getDate(new Date(d.data.create_time*1000))
						this.dataObj=Object.assign({},this.dataObj,d.data)
						
						//分享
						if(this.$root.isWeiXin()){
							//分享
							let query = '';
							if(this.$root.config.channel){
							 	query = `params=channelDY2FGoldUrlStrDY${this.$route.name}FGkeyNumDY1FGparamsKey1DYidFGparamsVal1DY${d.data.id}`
							}else{
							 	query = `params=oldUrlStrDY${this.$route.name}FGkeyNumDY2FGparamsKey1DYidFGparamsVal1DY${d.data.id}`
							}

							this.$root.wxShare({
								d:this.dataObj,//分享对象，题目等{title:'',title-img:''}
								query: query,//参数
								desc:this.dataObj.remark//分享详情
							})
						}
					}else{
						this.isShow = false;
						
					}
						
				})
			}
		}
	}
</script>

<style lang="scss">
	@import './articleDetail.scss';
</style>